package com.api.gbhg.luoao.flow;


import com.api.gbhg.liwenjun.GBHGConstant;
import com.api.gbhg.liwenjun.VersionFlowUtil;
import com.api.gbhg.luoao.tool.ToolCURD;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import java.util.HashMap;
import java.util.Map;

/**
 * 事业单位离退休人员工资津贴补贴经费需求表同步
 *
 */
public class CauseRetirementPay implements Action {
    private static final Logger LOGGER = LoggerFactory.getLogger(CauseRetirementPay.class);


    @Override
    public String execute(RequestInfo requestInfo) {
        //查询明细表
        RecordSet recordSet = ToolCURD.selectDetailnanlist(requestInfo, 1);
        double yszje = 0;
        while (recordSet.next()){
            String hjwy =  recordSet.getString("hjwy");

            if(!hjwy.isEmpty()){
                yszje = Double.parseDouble(hjwy)+yszje;
                if (yszje<0){
                    yszje=0;
                }
            }

        }
        //同步数据
        Map<String,String> stringStringMap = new HashMap<>();
        stringStringMap.put("xmmin","xmmc");//项目名称
        boolean b = VersionFlowUtil.sysDataToVersion(requestInfo.getRequestid(), requestInfo.getWorkflowid(),
                GBHGConstant.FlowVersionTableEnum.uf_sydwltxrygzjtbtj, stringStringMap);

        //把预算总金额插入到主表中
        boolean up = ToolCURD.updateVersionQuery( yszje, requestInfo.getRequestid());

        if (b&&up){
            return SUCCESS;
        }else {
        requestInfo.getRequestManager().setMessagecontent("数据同步失败!");
        requestInfo.getRequestManager().setMessageid("7763");
        return FAILURE_AND_CONTINUE;
        }


    }
}
